//
//  TXDateTimeService.m
//  TXKit
//
//  Created by YM on 15/3/13.
//  Copyright (c) 2015年 Tincent. All rights reserved.
//

#import "TXDateTimeService.h"

@implementation TXDateTimeService

/**
 * 单例方法，返回当前对象的实例
 *
 */
+ (TXDateTimeService *)sharedInstance
{
    static TXDateTimeService *_sharedObject = nil;
    
    static dispatch_once_t pred = 0;
    dispatch_once(&pred, ^{
        _sharedObject = [[self alloc] init];
    });
    
    return _sharedObject;
}

/**
 * 时间转换(时间戳->NSString)
 *
 * @param timeStamp               待转换的时间戳
 * @param format                      时间格式，比如 @"YYYY-MM-dd HH:mm:ss"
 * @return                字符串时间
 */
- (NSString *)stringFromTimeInterval:(NSTimeInterval )timeStamp format:(NSString *)format
{
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:timeStamp];

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:format];
    
    NSString *destDateString = [dateFormatter stringFromDate:date];
    
    return destDateString;
}

@end
